
// copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
// see COPYRIGHT for reuse legalities
//


#import "RIBTextureCoordinates.h"

@implementation RIBTextureCoordinates

+ initialize { return [RIBTextureCoordinates setVersion:1], self; }

- init
{
  [super init];
  s1 = 0;
  t1 = 0;
  s2 = 1;
  t2 = 0;
  s3 = 0;
  t3 = 1;
  s4 = 1;
  t4 = 1;

  return self;
}

- setS1:(RtFloat)newS1 t1:(RtFloat)newT1 s2:(RtFloat)newS2 t2:(RtFloat)newT2 s3:(RtFloat)newS3 t3:(RtFloat)newT3 s4:(RtFloat)newS4 t4:(RtFloat)newT4
{
  s1 = newS1;
  t1 = newT1;
  s2 = newS2;
  t2 = newT2;
  s3 = newS3;
  t3 = newT3;
  s4 = newS4;
  t4 = newT4;
  return self;
}

- setS1:(RtFloat)newS1  {  s1 = newS1;  return self; }
- (RtFloat)s1 { return s1; }
- setT1:(RtFloat)newT1  {  t1 = newT1;  return self; }
- (RtFloat)t1 { return t1; }

- setS2:(RtFloat)newS2  {  s2 = newS2;  return self; }
- (RtFloat)s2 { return s2; }
- setT2:(RtFloat)newT2  {  t2 = newT2;  return self; }
- (RtFloat)t2 { return t2; }

- setS3:(RtFloat)newS3  {  s3 = newS3;  return self; }
- (RtFloat)s3 { return s3; }
- setT3:(RtFloat)newT3  {  t3 = newT3;  return self; }
- (RtFloat)t3 { return t3; }

- setS4:(RtFloat)newS4  {  s4 = newS4;  return self; }
- (RtFloat)s4 { return s4; }
- setT4:(RtFloat)newT4  {  t4 = newT4;  return self; }
- (RtFloat)t4 { return t4; }

- (BOOL)theSameAs:otherRIBCommand
{
  if (s1 != [(RIBTextureCoordinates *)otherRIBCommand s1])
  {  return NO;
  }
  if (t1 != [(RIBTextureCoordinates *)otherRIBCommand t1])
  {  return NO;
  }
  if (s2 != [(RIBTextureCoordinates *)otherRIBCommand s2])
  {  return NO;
  }
  if (t2 != [(RIBTextureCoordinates *)otherRIBCommand t2])
  {  return NO;
  }
  if (s3 != [(RIBTextureCoordinates *)otherRIBCommand s3])
  {  return NO;
  }
  if (t3 != [(RIBTextureCoordinates *)otherRIBCommand t3])
  {  return NO;
  }
  if (s4 != [(RIBTextureCoordinates *)otherRIBCommand s4])
  {  return NO;
  }
  if (t4 != [(RIBTextureCoordinates *)otherRIBCommand t4])
  {  return NO;
  }

  return [super theSameAs:otherRIBCommand];
}



- renderSelf:(WW3DCamera *)camera  startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
{
  RiTextureCoordinates(s1, t1, s2, t2, s3, t3, s4, t4);

  return self;
}

- (unsigned long int)maxSampleBandwidth {  return ([super maxSampleBandwidth] + (unsigned long int)(8 * sizeof(RtFloat))); }


- writeEve:(NXStream *)stream atTabLevel:(int)tab
{
   int  i;


   for (i = 0; i < tab; i++)
   {  NXPrintf(stream, "\t");
   }
   NXPrintf(stream, "TextureCoordinates %f %f %f %f %f %f %f %f;", s1, t1, s2, t2, s3, t3, s4, t4);
   return self;
}

- read:(NXTypedStream*)stream 
{
    int version;
    [super read:stream];

NX_DURING
    version = NXTypedStreamClassVersion(stream,"RIBTextureCoordinates");
    if (version == 0) NXReadTypes(stream,"i",&version), version=1;
    if (version == 1)
    {  NXReadTypes(stream, "ffffff", &s1, &t1, &s2, &t2, &s3, &t3, &s4, &t4);
    } 
NX_HANDLER
   NXLogError("in read: %s, exception [%d] raised.\n", 
                 [[self class] name], NXLocalHandler.code);
   return nil;
NX_ENDHANDLER
    return self;
}

- write:(NXTypedStream*)stream 
{
    [super write:stream];

    NXWriteTypes(stream, "ffffff", &s1, &t1, &s2, &t2, &s3, &t3, &s4, &t4);

    return self;
}


@end
